package com.spring.campus_express_delivery.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;

import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


import java.nio.file.Path;
import java.util.ArrayList;

@Configuration
@EnableSwagger2 //开启Swagger2
public class SwaggerConfig {
    //多个Docket实现多组
    @Bean
    public Docket docket1(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("A")
                .select()
                .apis(RequestHandlerSelectors.none())
                .build();
    }
    @Bean
    public Docket docket2(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("B")
                .select()
                .apis(RequestHandlerSelectors.none())
                .build();
    }
    @Bean
    public Docket docket3(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("C")
                .select()
                .apis(RequestHandlerSelectors.none())
                .build();
    }



    //配置了Swagger的Bean实例
    @Bean
    public Docket docket(Environment environment){
        //设置要显示的Swagger环境
        Profiles prfiles= Profiles.of("dev","test");
        //通过environment.acceptsProfiles判断是否出处在自己设定的环境当中
        boolean flag=environment.acceptsProfiles(prfiles);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("GY1016")
                .enable(true)//enable是否启动Swagger，如果为false不启动，则不能在浏览器里访问Swagger如果为true启动Swagger
                .select()
                //RequestHandlerSelectors 扫描要配置接口的方式
                //basePackage 指定要扫描的包
                .apis(RequestHandlerSelectors.basePackage("com.spring.campus_express_delivery.controller"))
                //any():扫描全部
                //none():全不扫描
                //withClassAnnotation:扫描类上的注解
                //withMethodAnnotation:扫描方法上的注解
                //.apis(RequestHandlerSelectors.any())
                //paths():过滤路径
               // .paths(PathSelectors.ant("/controller/"))
                .build();
    }
    //配置Swagger信息=apiInfo
    private ApiInfo apiInfo(){
        //作者信息
        Contact contact=new Contact("dxj1016","http://www.apache.org/licenses/LICENSE-2.0","1278065208@qq.com");
        return new ApiInfo("Jiao同学的SwaggerAPI文档",
                "炖了毛球好下饭",
                "v1.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList()
        );
    }
}
